#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int n = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int arr[1001][2] = { 0 };
		int id, hour, min;
		char ch = 0;
		int count = 0;
		int time = 0;
		do {
			scanf("%d %c %d:%d", &id, &ch, &hour, &min);
			if (ch == 'S') {
				arr[id][0] = 1;
				arr[id][1] = hour * 60 + min;
			}
			if (ch == 'E') {
				if (arr[id][0] == 1) {
					count++;
					time += -arr[id][1] + hour * 60 +min;
					arr[id][0] = 0;
				}
			}

		} while (id);
		if (count == 0) {
			printf("0 0\n");
		}
		else {
			printf("%d %.0f\n", count, 1.0*time/count);
		}
	}
	return 0;
}